using System;

namespace OpenWaves.Caching
{
    public class HttpCacheWrapper<T> : ICache<T> where T : class
    {
        private readonly System.Web.Caching.Cache innerCache;
        private readonly string keyPrefix;

        public HttpCacheWrapper(System.Web.Caching.Cache innerCache, string keyPrefix)
        {
            this.innerCache = innerCache;
            this.keyPrefix = keyPrefix;
        }

        public void InsertValue(string key, T value, DateTime absoluteExpiration)
        {
            this.innerCache.Insert(this.keyPrefix + key, value, null, absoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration);
        }

        public void EvictValue(string key)
        {
            this.innerCache.Remove(this.keyPrefix + key);
        }

        public T GetValue(string key)
        {
            return (T) this.innerCache.Get(this.keyPrefix + key);
        }
    }
}